package com.example.mykotlinapp

import java.lang.StringBuilder

/**
 *
 *
 * @author zhudeshuai
 * @since 2019/7/8
 */

//创建序列
private fun test90() {
    val naturalNumbers = generateSequence(0) { it + 1 }
    val numbersTo100 = naturalNumbers.takeWhile { it <= 100 }
    println(numbersTo100.sum())
}

//with使用

private fun alphabet() = with(StringBuilder()) {
    for (letter in 'A'..'Z') {
        append(letter)
    }
    append("\nNow I know the alphabet!")
    toString()
}

//apply
private fun alphabet2() = StringBuilder().apply {
    for (letter in 'A'..'Z') {
        append(letter)
    }
    append("\nNow I know the alphabet!")
}.toString()


//可空性
private fun test91(s: String) {}

private fun test92(s: String?) {}
private fun getStrLen(s: String?): Int {
    return s?.length ?: 0
}

private fun main() {

}